var paramlist = new Array();
var adddedCount = 0;
var app = 'https://www.uhuijia.com.cn/mall/mobile/'
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '特价清仓秋季美衣' //页面标题为路由参数
    })
    var that = this;
    paramlist = new Array();
    // 数量初始化
    adddedCount = 1;
    that.setData({
      adddedCount: adddedCount
    })
    // appId = app.globalData.appId;
    // token = wx.getStorageSync("token");
    // identity = wx.getStorageSync("identity");
    var spuid = 'f55658e1ad46458a9b27c1f7c311c07d';
    that.goodsdetail(spuid);
    // that.goodsjudge(spuid);
    // that.goodsparam(spuid);
    that.tabConheight();
  },
  // 进店铺
  tostore:function(){
    wx.navigateTo({
      url: '/pages/storeinfo/storeinfo',
    })
  },
  goodsparam: function (id) {
    var that = this;
    that.getchoosedParam();
    wx.request({
      url: app + '/yh2/getSkuPropertys2',
      data: {
        spuId: id,
        queryParam: that.data.queryParam
      },
      success: function (res) {
        console.log(res);
        if (res.data.code == "10000") {
          paramlist = res.data.data.propertys;
          skus = res.data.data.sku;
          skuid = skus.skuId
          that.setData({
            paramlist: paramlist,
            skus: skus,
            skuid: skuid
          })
        }
      }
    })
  },
  goodsdetail: function (id) {
    var that = this;
    wx.request({
      url: app + '/yh2/detail2',
      data: {
        id: id
      },
      success: function (res) {
        // console.log(res);
        if (res.data.code == "10000") {
          goodsinfo = res.data.data;
          goodsimg = res.data.data.banner;
          detailinfo = res.data.data.detailImages;
          skuid = res.data.data.mainSkuId;
          // console.log(goodsimg)
          that.setData({
            goodsimg: goodsimg,
            goodsinfo: goodsinfo,
            detailinfo: detailinfo,
            skuid: skuid
          })
        } else {
          wx.showToast({
            title: res.data.msg,
          })
        }
      }
    })
  },
  //滑动切换
  swiperTab: function (e) {
    var that = this;
    that.setData({
      currentTba: e.detail.current
    });
  },
  //点击切换
  clickTab: function (e) {

    var that = this;

    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  goodsjudge: function (id) {
    var that = this;
    wx.request({
      url: app + '/yh2/getSpuFeedbacks2',
      data: {
        id: id,
        'type': isHaveImg,
        like: like,
        start: 0,
        length: 10
      },
      success: function (res) {
        console.log(res);
        if (res.data.code == "10000") {
          judgelist = res.data.data.list;
          // var judgeImg = new Array();
          // for(var i=0;i<judgelist.length;i++){
          //   judgelist[i].images.replace("[",'');
          //   judgelist[i].images.replace("]", '');
          //   var jugjudgelist[i].images.split(",");
          //   judgeImg.push(judgelist[i].images);
          // }
          that.setData({
            judgelist: judgelist
          })
        }
      }
    })
  },
  /**
   * 计算tab高度
   */
  tabConheight: function () {
    var that = this;
    var query = wx.createSelectorQuery();

    var tablistEnjoyConHeight = "";
    var bottomBtnConHeight = "";

    query.select('#tablistEnjoyCon').boundingClientRect()
    query.select('#bottomBtnCon').boundingClientRect()
    query.exec(function (res) {
      tablistEnjoyConHeight = res[0].height;
      bottomBtnConHeight = res[1].height;
      wx.getSystemInfo({
        success: function (res) {
          that.setData({
            tabConheight: res.windowHeight - tablistEnjoyConHeight - bottomBtnConHeight
          });
        }
      });
    });
  },

  /**
   * 开启选择规格
   */
  showFormat: function () {
    var that = this;
    that.setData({
      showFormatCon: true
    })
  },
  showCoupon: function () {
    var that = this;
    that.setData({
      showCoupon: true
    })
  },

  /**
   * 关闭选择规格
   */
  closeFormatCon: function () {
    var that = this;
    that.setData({
      showFormatCon: false
    })
  },
  closeCoupon: function () {
    var that = this;
    that.setData({
      showCoupon: false
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})